/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.storebits.testsystem;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 *
 * @author Ventsi
 */
@Entity
@Table(name = "journeyreservation")
@NamedQueries({
    @NamedQuery(name = "Journeyreservation.findAll", query = "SELECT j FROM Journeyreservation j")})
public class Journeyreservation implements Serializable {
    @Basic(optional = false)
    @NotNull
    @Column(name = "seats")
    private int seats;
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "deposit")
    private BigDecimal deposit = new BigDecimal(0);
    @Basic(optional = false)
    @NotNull
    @Column(name = "totalSum")
    private BigDecimal totalSum = new BigDecimal(0);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "idReservation")
    private Integer idReservation = new Integer(0);
    @JoinColumn(name = "journey", referencedColumnName = "catalogNumber")
    @ManyToOne
    private Journey journey;
    @NotNull
    @Column(name = "startDate")
    @Temporal(TemporalType.DATE)
    private Date startDate;
    @NotNull
    @Column(name = "endDate")
    @Temporal(TemporalType.DATE)
    private Date endDate;
    @JoinColumn(name = "customer", referencedColumnName = "USERNAME")
    @OneToOne(optional = false)
    private Users customer;

    public Journeyreservation() {
    }

    public Journeyreservation(Integer idReservation) {
        this.idReservation = idReservation;
    }

    public Journeyreservation(int seats, Journey journey, Users customer) {
        this.seats = seats;
        this.journey = journey;
        this.customer = customer;
    }
    
    public Integer getIdReservation() {
        return idReservation;
    }

    public void setIdReservation(Integer idReservation) {
        this.idReservation = idReservation;
    }

    public Journey getJourney() {
        return journey;
    }

    public void setJourney(Journey journey) {
        this.journey = journey;
    }

    public BigDecimal getDeposit() {
        return deposit;
    }

    public void setDeposit(BigDecimal deposit) {
        this.deposit = deposit;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idReservation != null ? idReservation.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Journeyreservation)) {
            return false;
        }
        Journeyreservation other = (Journeyreservation) object;
        if ((this.idReservation == null && other.idReservation != null) || (this.idReservation != null && !this.idReservation.equals(other.idReservation))) {
            return false;
        }
        return true;
    }
    

    @Override
    public String toString() {
        return "com.storebits.testsystem.Journeyreservation[ idReservation=" + idReservation + " ]";
    }

    public int getSeats() {
        return seats;
    }

    public void setSeats(int seats) {
        System.out.println("setSeats(" + seats + ")");
        this.seats = seats;
    }

    public BigDecimal getTotalSum() {
        return totalSum;
    }

    public void setTotalSum(BigDecimal sum ) {
        //double sum = seats * journey.getPrice().doubleValue();
        //this.totalSum = BigDecimal.valueOf(sum);
        this.totalSum = sum;
    }

    public Users getCustomer() {
        return customer;
    }

    public void setCustomer(Users customer) {
        this.customer = customer;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }
    
}
